package com.study.dao.impl;

import com.study.dao.UserDao;
import com.study.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.HibernateTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Administrator on 2017/10/24.
 */
@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private HibernateTemplate hibernateTemplate;
    @Override
    public User findUser(User user) {
        List<User> userList = hibernateTemplate.findByExample(user);
        if(userList.size()==1){
            return userList.get(0);
        }else{
            return null;
        }
    }

    @Override
    public User findOneById(Integer id) {
        return (User) hibernateTemplate.get("User",id);
    }

    @Override
    public List<User> findList(User user) {
        return hibernateTemplate.findByExample(user);
    }

    @Override
    public int updateOne(User user) {
        hibernateTemplate.update(user);
        return 1;
    }

    @Override
    public int saveOne(User user) {
        return (int) hibernateTemplate.save(user);
    }

    @Override
    public int deleteById(Integer id) {
        return 0;
    }
}
